<?php
session_start();
//require_once("../config/include.inc.php");
require_once("../config/include_tokyo.inc.php");

//访问权限验证
$userRole = $_SESSION['user_role'];
if($userRole == 1 || $userRole == 4 || $userRole == 5){
	//管理员,订单管理员,任务管理员+订单管理员
}else{
	if($userRole > 0){
		$url = "../index.php?loginError=2";//没权限
	}else{
		$url = "../index.php?loginError=3";//没登录
	}	
	echo "<script language='javascript' type='text/javascript'>";
	echo "window.location.href='$url'";
	echo "</script>";
}


//更新订单内容
$doFlag = $_POST["doFlag"];
if($doFlag == "doUpdate"){
	$id = $_POST["id"];
	$_GET['id'] = $id;
	$validateFlag = true;
    $sqlError = "";

	$bank_time_str =  $_POST["bank_time"];
	$bank_time = strtotime($bank_time_str." 03:00:00");
	if($bank_time == "" || $bank_time == false || $bank_time == -1){
		$validateFlag = false;
		$sqlError = $insertError."  转帐时间格式不对";
	}else{
		$bank_time = date("Y-m-d",$bank_time); 
	}
	$bank_amount =  $_POST["bank_amount"];
	$bank_amount = str_replace(",","",$bank_amount);
	$bank_amount = trim($bank_amount);
	if(eregi("^[0-9]+$",$bank_amount)){
		//是数字	
		if($transfer_flag == "1" && $bank_amount > 0){
			//资金转出
			$bank_amount = $bank_amount*-1;
		}
		
	}else{
		$validateFlag = false;
		$sqlError = $sqlError."  金额只能是数字";
	}
	if($owner_flag == 0 && $order_no == "" && $transfer_flag == "0"){
		$validateFlag = false;
		$sqlError = $sqlError."  订单编号不能为空";
	}
	$bank_note = $_POST["bank_note"];
	$transfer_flag = $_POST["transfer_flag"];
	$owner_flag = $_POST["owner_flag"];
	$order_no = $_POST["order_no"];
	$customer_name = $_POST["customer_name"];
	$our_note = $_POST["our_note"];

	if($validateFlag){
		$sql = "update banktransfer set bank_time = '".$bank_time."'";
		$sql = $sql.", bank_amount= ".$bank_amount;
		$sql = $sql.", bank_note='".$bank_note."'";
		$sql = $sql.", owner_flag= ".$owner_flag;
		$sql = $sql.", order_no='".$order_no."'";
		$sql = $sql.", customer_name='".$customer_name."'";
		$sql = $sql.", our_note='".$our_note."'";
		$sql = $sql.", transfer_flag= ".$transfer_flag;
		$sql = $sql."  where id=".$id;	
		$db->Execute($sql);	
	}else{
		echo $sqlError;
	}

	
	
	

	$db->Execute($sql);
}


//订单详情 
$id = $_GET['id'];
if($id == ""){
	//新增订单
}else{
	//编辑订单
	$sql = "SELECT * from banktransfer where id=".$id;
	$result = $db->Execute($sql);
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<!--Begin:head-->
<? $pageTitle = "银行转帐详情"; ?>
<?php include("../head.php"); ?>
<!--End:head-->


<body>
<?php include("../topMenu.php"); ?>


<form name="inputForm" action="../bank/bankInput.php" method="post">
<div id="container" >	
<div class="grayTable">	
<h4>银行转帐详情:
<?php  if($doFlag == "doUpdate"){echo "银行转帐更新成功!";}?>
</h4>
<table >
<thead>
	<tr>
		<th scope="col" width=90 >字段名称</th>
	    <th scope="col" >字段值</th>		
	</tr>
</thead>

<?php
if (!empty($result)) {
	$bank_time = date('Y-m-d',strtotime($result->fields['bank_time']));

	$strTR = "";
	$strTR = $strTR."<tr ><td>ID</td>";
	$strTR = $strTR."<td>".$id."</td></tr>";
	$strTR = $strTR."<tr ><td>转帐时间</td>";
	$strTR = $strTR."<td><input type='text' name='bank_time' id='bank_time' value='".$bank_time."' size=20></td></tr>";
	$strTR = $strTR."<tr ><td>转帐金额</td>";
	$strTR = $strTR."<td><input type='text' name='bank_amount' id='bank_amount' value='".$result->fields['bank_amount']."' size=20></td></tr>";
	$strTR = $strTR."<tr ><td>银行摘要</td>";
	$strTR = $strTR."<td><input type='text' name='bank_note' id='bank_note' value='".$result->fields['bank_note']."' size=20></td></tr>";
	$strTR = $strTR."<tr ><td>记录类型</td>";
	$strTR = $strTR."<td><input type='text' name='transfer_flag' id='transfer_flag' value='".$result->fields['transfer_flag']."' size=20><br>(0=转入 1=转出 2=疑问 3=小结)</td></tr>";
	$strTR = $strTR."<tr ><td>资金流向</td>";
	$strTR = $strTR."<td><input type='text' name='owner_flag' id='owner_flag' value='".$result->fields['owner_flag']."' size=20><br>(0=Vincent 1=LiuYi)</td></tr>";
	$strTR = $strTR."<tr ><td>订单编号</td>";
	$strTR = $strTR."<td><input type='text' name='order_no' id='order_no' value='".$result->fields['order_no']."' size=20></td></tr>";
	$strTR = $strTR."<tr ><td>客户名字</td>";
	$strTR = $strTR."<td><input type='text' name='customer_name' id='customer_name' value='".$result->fields['customer_name']."' size=20></td></tr>";
	$strTR = $strTR."<tr ><td>备注</td>";
	$strTR = $strTR."<td><input type='text' name='our_note' id='our_note' value='".$result->fields['our_note']."' size=20></td></tr>";

	$strTR = $strTR."<tr><td colspan=2 align=center>";
	$strTR = $strTR."<input type='button' value='保存' onclick='doUpdate(".$id.")'>";
	$strTR = $strTR."<input type='button' value='返回' onClick='toList()'>";
	$strTR = $strTR."</td></tr>";
	echo $strTR;
}

?>

</table>



</div>

<br><br>
<br><br>

</div><!--end container -->

<input type="hidden" name="doFlag" id="doFlag" >
<input type="hidden" name="id" id="id" >
</form>
</body>




</html>

<script>


function doUpdate(id){
	document.getElementById('doFlag').value = 'doUpdate';
	document.getElementById('id').value = id;
	document.inputForm.submit();
}


function toList(){
	window.location.href = "bankList.php";
}
</script>

